import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;

public class maincms {
    //获取数据库连接
    static sqlconnect sqlcnt = new sqlconnect();
    public static String usertype = null;
    public static String nowusername;
    public static String nowuserpassword;
    public static student loginstudent = new student();
    public static teacher loginteacher = new teacher();
    public static admin loginadmin = new admin();
    public static student[] studentresult = new student[100];
    public static teacher[] teacherresult = new teacher[100];
    public static course[] courseresult = new course[100];
    public static cselect[] csresult = new cselect[100];
    public static Vector<String> resultvector = new Vector<>();
    public static String str;
    public static int flag;
    public static int i = 0;

    public static void main(String[] args) {
        for (i = 0; i < 100; i++) {
            studentresult[i] = new student();
            teacherresult[i] = new teacher();
            courseresult[i] = new course();
            csresult[i] = new cselect();
        }
        //获取数据库连接
        showui();
    }

    public static void showui() {
        JFrame frame = new JFrame("选课管理系统");//创建Frame窗口
        frame.setBounds(300, 200, 800, 500);
        frame.setResizable(false);
        frame.setVisible(true);
        JPanel p1 = new JPanel();//登录面板
        JPanel p2 = new JPanel();//注册总界面
        JPanel p3 = new JPanel();//学生注册界面
        JPanel p4 = new JPanel();//教师注册界面
        JPanel p5 = new JPanel();//学生操作面板
        JPanel p6 = new JPanel();//学生个人信息面板
        JPanel p7 = new JPanel();//教师操作面板
        JPanel p8 = new JPanel();//教师个人信息面板
        JPanel p9 = new JPanel();//管理员操作面板
        JPanel p10 = new JPanel();//管理员信息面板
        JPanel p11 = new JPanel();//教师添加课程面板
        JPanel cards = new JPanel(new CardLayout());
        cards.add(p1, "loginpanel");
        cards.add(p2, "regiterpanel");
        cards.add(p3, "studentregiterpanel");
        cards.add(p4, "teacherregiterpanel");
        cards.add(p5, "studentoperationpanel");
        cards.add(p6, "studentinformationpanel");
        cards.add(p7, "teacheroperationpanel");
        cards.add(p8, "teacherinformationpanel");
        cards.add(p9, "adminoperationpanel");
        cards.add(p10, "admininformationpanel");
        cards.add(p11, "teacheraddcoursepanel");
        //登录界面组件
        JLabel usernamelabel = new JLabel("请输入用户名:");
        JTextField usernametext = new JTextField("", 30);
        JLabel userpasswordlabel = new JLabel("请输入密码:");
        JPasswordField userpasswordtext = new JPasswordField("", 30);
        JButton loginbutton = new JButton("登录");
        JLabel nothaveuserlabel = new JLabel("还没有账号？");
        JButton registerbutton = new JButton("立即注册");
        //登录面板创建
        p1.add(usernamelabel);
        p1.add(usernametext);
        p1.add(userpasswordlabel);
        p1.add(userpasswordtext);
        p1.add(loginbutton);
        p1.add(nothaveuserlabel);
        p1.add(registerbutton);
        //注册总界面组件
        JLabel registerlabel = new JLabel("请选择注册身份");
        JButton studentregisterbutton = new JButton("学生注册");
        JButton teacherregisterbutton = new JButton("教师注册");
        JLabel registerhaveuserlabel = new JLabel("已有账号？");
        JButton registergotologinbutton = new JButton("立即登录");
        //注册总界面创建
        p2.add(registerlabel);
        p2.add(studentregisterbutton);
        p2.add(teacherregisterbutton);
        p2.add(registerhaveuserlabel);
        p2.add(registergotologinbutton);
        //学生注册界面组件
        JLabel studentregisterlabel = new JLabel("请填写并确认下列信息（全部为必填项）");
        JLabel setsnolabel = new JLabel("请输入用户名（学号）：");
        JTextField setsnotext = new JTextField("请输入用户名（学号）", 30);
        JLabel setsnamelabel = new JLabel("请输入姓名：");
        JTextField setsnametext = new JTextField("请输入姓名", 30);
        JLabel setssexlabel = new JLabel("请选择性别：");
        JComboBox setssexcmobox = new JComboBox();
        setssexcmobox.addItem("请选择性别");
        setssexcmobox.addItem("男");
        setssexcmobox.addItem("女");
        JLabel setsagelabel = new JLabel("请输入年龄：");
        JTextField setsagetext = new JTextField("请输入年龄", 30);
        JLabel setprosslabel = new JLabel("请输入专业：");
        JTextField setprosstext = new JTextField("请输入专业", 30);
        JLabel setspwdlabel = new JLabel("请输入密码：");
        JPasswordField setspwdtext = new JPasswordField("", 30);
        JLabel setspwdconfirmlabel = new JLabel("再次输入密码：");
        JPasswordField setspwdconfirmtext = new JPasswordField("", 30);
        JButton studentregisterconfirmbutton = new JButton("确认注册");
        JButton studentregisterreturnbutton = new JButton("重新选择注册身份");
        //学生注册界面创建
        p3.add(studentregisterlabel);
        p3.add(setsnolabel);
        p3.add(setsnotext);
        p3.add(setsnamelabel);
        p3.add(setsnametext);
        p3.add(setssexlabel);
        p3.add(setssexcmobox);
        p3.add(setsagelabel);
        p3.add(setsagetext);
        p3.add(setprosslabel);
        p3.add(setprosstext);
        p3.add(setspwdlabel);
        p3.add(setspwdtext);
        p3.add(setspwdconfirmlabel);
        p3.add(setspwdconfirmtext);
        p3.add(studentregisterconfirmbutton);
        p3.add(studentregisterreturnbutton);
        //教师注册界面组件
        JLabel teacherregisterlabel = new JLabel("请填写并确认下列信息（全部为必填项）");
        JLabel settnolabel = new JLabel("请输入用户名（工号）：");
        JTextField settnotext = new JTextField("请输入用户名（工号）", 30);
        JLabel settnamelabel = new JLabel("请输入姓名：");
        JTextField settnametext = new JTextField("请输入姓名", 30);
        JLabel settsexlabel = new JLabel("请选择性别：");
        JComboBox settsexcmobox = new JComboBox();
        settsexcmobox.addItem("请选择性别");
        settsexcmobox.addItem("男");
        settsexcmobox.addItem("女");
        JLabel settagelabel = new JLabel("请输入年龄：");
        JTextField settagetext = new JTextField("请输入年龄", 30);
        JLabel settptlabel = new JLabel("请选择职称：");
        JComboBox settptcmobox = new JComboBox();
        settptcmobox.addItem("请选择职称");
        settptcmobox.addItem("助教");
        settptcmobox.addItem("讲师");
        settptcmobox.addItem("副教授");
        settptcmobox.addItem("教授");
        JLabel settpwdlabel = new JLabel("请输入密码：");
        JPasswordField settpwdtext = new JPasswordField("", 30);
        JLabel settpwdconfirmlabel = new JLabel("再次输入密码：");
        JPasswordField settpwdconfirmtext = new JPasswordField("", 30);
        JButton teacherregisterconfirmbutton = new JButton("确认注册");
        JButton teacherregisterreturnbutton = new JButton("重新选择注册身份");
        //教师注册界面创建
        p4.add(teacherregisterlabel);
        p4.add(settnolabel);
        p4.add(settnotext);
        p4.add(settnamelabel);
        p4.add(settnametext);
        p4.add(settsexlabel);
        p4.add(settsexcmobox);
        p4.add(settagelabel);
        p4.add(settagetext);
        p4.add(settptlabel);
        p4.add(settptcmobox);
        p4.add(settpwdlabel);
        p4.add(settpwdtext);
        p4.add(settpwdconfirmlabel);
        p4.add(settpwdconfirmtext);
        p4.add(teacherregisterconfirmbutton);
        p4.add(teacherregisterreturnbutton);
        //学生操作面板组件
        JLabel studentinformationlabel = new JLabel();
        JButton studentquitbutton = new JButton("退出登录");
        JButton studentprivateinformationbutton = new JButton("个人信息");
        studentinformationlabel.setHorizontalAlignment(SwingConstants.CENTER);
        JComboBox studentfindcoursecombobox = new JComboBox();
        studentfindcoursecombobox.addItem("请选择查询方式（不选择将查询所有课程）");
        studentfindcoursecombobox.addItem("按课程号查询");
        studentfindcoursecombobox.addItem("按课程名查询");
        studentfindcoursecombobox.addItem("按课程主讲老师查询");
        studentfindcoursecombobox.addItem("按学分查询");
        studentfindcoursecombobox.addItem("查询我已选的课程");
        studentfindcoursecombobox.addItem("查询未选满的课程");
        JTextField studentfindkeytext = new JTextField("请输入课程查询的关键字", 30);
        JButton studentfindcoursebutton = new JButton("查询课程");
        JButton studentselectcoursebutton = new JButton("选课");
        JButton studentdeletecoursebutton = new JButton("退课");
        //列表和表格创建
        JList courselist = new JList();
        courselist.setPreferredSize(new Dimension(750, 300));
        courselist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        //学生操作面板创建
        p5.add(studentinformationlabel);//登录信息
        p5.add(studentprivateinformationbutton);//个人信息按钮
        p5.add(studentquitbutton);
        p5.add(studentfindcoursecombobox);
        p5.add(studentfindkeytext);
        p5.add(studentfindcoursebutton);//查询按钮
        p5.add(courselist);//列表
        p5.add(studentselectcoursebutton);//选课按钮
        p5.add(studentdeletecoursebutton);//退课按钮
        //学生个人信息面板组件
        JLabel studentallinformationlabel = new JLabel("个人信息：");
        JLabel studentsnolabel = new JLabel("用户名（学号）：");
        JTextField studentsnotext = new JTextField("", 30);
        JLabel studentsnamelabel = new JLabel("姓名：");
        JTextField studentsnametext = new JTextField("", 30);
        JLabel studentssexlabel = new JLabel("性别：");
        JTextField studentssextext = new JTextField("", 30);
        JLabel studentsagelabel = new JLabel("年龄：");
        JTextField studentsagetext = new JTextField("", 30);
        JLabel studentprosslabel = new JLabel("专业：");
        JTextField studentprosstext = new JTextField("", 30);
        JLabel studentspwdlabel = new JLabel("密码：");
        JTextField studentspwdtext = new JTextField("", 30);
        JButton studentupdateconfirmbutton = new JButton("保存更改");
        JButton studentallinformationreturnbutton = new JButton("返回");
        //学生个人信息面板创建
        p6.add(studentallinformationlabel);
        p6.add(studentsnolabel);
        p6.add(studentsnotext);
        p6.add(studentsnamelabel);
        p6.add(studentsnametext);
        p6.add(studentssexlabel);
        p6.add(studentssextext);
        p6.add(studentsagelabel);
        p6.add(studentsagetext);
        p6.add(studentprosslabel);
        p6.add(studentprosstext);
        p6.add(studentspwdlabel);
        p6.add(studentspwdtext);
        p6.add(studentupdateconfirmbutton);
        p6.add(studentallinformationreturnbutton);
        //教师操作面板组件
        JLabel teacherinformationlabel = new JLabel();
        JButton teacherquitbutton = new JButton("退出登录");
        JButton teacherprivateinfomationbutton = new JButton("个人信息");
        teacherinformationlabel.setHorizontalAlignment(SwingConstants.CENTER);
        JButton teacheraddcoursebutton = new JButton("添加课程");
        JButton teacherfindstudentbutton = new JButton("查询我的学生");
        JList teacherselectlist = new JList();
        teacherselectlist.setPreferredSize(new Dimension(750, 300));
        //教师操作面板创建
        p7.add(teacherinformationlabel);//登录信息
        p7.add(teacherquitbutton);
        p7.add(teacherprivateinfomationbutton);
        p7.add(teacheraddcoursebutton);
        p7.add(teacherfindstudentbutton);
        p7.add(teacherselectlist);
        //教师个人信息面板组件
        JLabel teacherallinformationlabel = new JLabel("个人信息：");
        JLabel teachertnolabel = new JLabel("用户名（工号）：");
        JTextField teachertnotext = new JTextField("", 30);
        JLabel teachertnamelabel = new JLabel("姓名：");
        JTextField teachertnametext = new JTextField("", 30);
        JLabel teachertsexlabel = new JLabel("性别：");
        JTextField teachertsextext = new JTextField("", 30);
        JLabel teachertagelabel = new JLabel("年龄：");
        JTextField teachertagetext = new JTextField("", 30);
        JLabel teachertptlabel = new JLabel("职称：");
        JTextField teachertpttext = new JTextField("", 30);
        JLabel teachertpwdlabel = new JLabel("密码：");
        JTextField teachertpwdtext = new JTextField("", 30);
        JButton teacherupdateconfirmbutton = new JButton("保存更改");
        JButton teacherallinformationreturnbutton = new JButton("返回");
        //教师个人信息面板创建
        p8.add(teacherallinformationlabel);
        p8.add(teachertnolabel);
        p8.add(teachertnotext);
        p8.add(teachertnamelabel);
        p8.add(teachertnametext);
        p8.add(teachertsexlabel);
        p8.add(teachertsextext);
        p8.add(teachertagelabel);
        p8.add(teachertagetext);
        p8.add(teachertptlabel);
        p8.add(teachertpttext);
        p8.add(teachertpwdlabel);
        p8.add(teachertpwdtext);
        p8.add(teacherupdateconfirmbutton);
        p8.add(teacherallinformationreturnbutton);
        //教师添加课程界面组件
        JLabel courseregisterlabel = new JLabel("请填写并确认下列信息（全部为必填项）");
        JLabel setcnolabel = new JLabel("请输入课程号：");
        JTextField setcnotext = new JTextField("请输入课程号", 30);
        JLabel setcnamelabel = new JLabel("请输入课程名：");
        JTextField setcnametext = new JTextField("请输入课程名", 30);
        JLabel setcreditlabel = new JLabel("请输入课程学分：");
        JTextField setcredittext = new JTextField("请输入课程学分", 30);
        JLabel setcapacitylabel = new JLabel("请输入课程容量：");
        JTextField setcapacitytext = new JTextField("请输入课程容量", 30);
        JButton courseregisterconfirmbutton = new JButton("确认添加");
        JButton teacheraddcoursereturnbutton = new JButton("返回");
        //教师添加课程界面创建
        p11.add(courseregisterlabel);
        p11.add(setcnolabel);
        p11.add(setcnotext);
        p11.add(setcnamelabel);
        p11.add(setcnametext);
        p11.add(setcreditlabel);
        p11.add(setcredittext);
        p11.add(setcapacitylabel);
        p11.add(setcapacitytext);
        p11.add(courseregisterconfirmbutton);
        p11.add(teacheraddcoursereturnbutton);
        //管理员操作面板组件
        JLabel admininformationlabel = new JLabel();
        JButton adminquitbutton = new JButton("退出登录");
        JButton adminprivateinformationbutton = new JButton("管理员信息");
        admininformationlabel.setHorizontalAlignment(SwingConstants.CENTER);
        JTextField adminfindkeytext = new JTextField("请输入查询的关键字", 30);
        JComboBox adminfindstudentcombobox = new JComboBox();//查询学生
        adminfindstudentcombobox.addItem("请选择查询方式（不选择将查询所有学生）");
        adminfindstudentcombobox.addItem("按学号查询");
        adminfindstudentcombobox.addItem("按学生姓名查询");
        adminfindstudentcombobox.addItem("按专业查询");
        JButton adminfindstudentbutton = new JButton("查询学生信息");
        JComboBox adminfindteachercombobox = new JComboBox();//查询教师
        adminfindteachercombobox.addItem("请选择查询方式（不选择将查询所有教师）");
        adminfindteachercombobox.addItem("按工号查询");
        adminfindteachercombobox.addItem("按教师姓名查询");
        adminfindteachercombobox.addItem("按职称查询");
        JButton adminfindteacherbutton = new JButton("查询教师信息");
        JComboBox adminfindcoursecombobox = new JComboBox();//查询课程
        adminfindcoursecombobox.addItem("请选择查询方式（不选择将查询所有课程）");
        adminfindcoursecombobox.addItem("按课程号查询");
        adminfindcoursecombobox.addItem("按课程名查询");
        adminfindcoursecombobox.addItem("按课程主讲老师查询");
        adminfindcoursecombobox.addItem("按学分查询");
        JButton adminfindcoursebutton = new JButton("查询课程信息");
        JComboBox adminfindcselectcombobox = new JComboBox();//查询注册信息
        adminfindcselectcombobox.addItem("请选择查询方式（不选择将查询所有选课）");
        adminfindcselectcombobox.addItem("按课程号查询");
        adminfindcselectcombobox.addItem("按学生学号查询");
        adminfindcselectcombobox.addItem("按教师工号查询");
        JButton adminfindcselectbutton = new JButton("查询选课信息");
        JList adminselectlist = new JList();
        adminselectlist.setPreferredSize(new Dimension(750, 300));
        JButton admindeleterbutton = new JButton("删除记录");
        //管理员操作面板创建
        p9.add(admininformationlabel);//登录信息
        p9.add(adminquitbutton);
        p9.add(adminprivateinformationbutton);
        p9.add(adminfindkeytext);
        p9.add(adminfindstudentcombobox);
        p9.add(adminfindstudentbutton);//查询学生信息按钮
        p9.add(adminfindteachercombobox);
        p9.add(adminfindteacherbutton);//查询教师信息按钮
        p9.add(adminfindcoursecombobox);
        p9.add(adminfindcoursebutton);//查询课程信息按钮
        p9.add(adminfindcselectcombobox);
        p9.add(adminfindcselectbutton);//查询注册信息按钮
        p9.add(adminselectlist);
        p9.add(admindeleterbutton);
        //管理员信息面板
        JLabel adminallinformationlabel = new JLabel("管理员信息：");
        JLabel adminadnolabel = new JLabel("管理员号：");
        JTextField adminadnotext = new JTextField("", 30);
        JLabel adminadnamelabel = new JLabel("姓名：");
        JTextField adminadnametext = new JTextField("", 30);
        JLabel adminadpwdlabel = new JLabel("密码：");
        JTextField adminadpwdtext = new JTextField("", 30);
        JButton adminupdateconfirmbutton = new JButton("保存更改");
        JButton adminallinformationreturnbutton = new JButton("返回");
        //管理员信息面板创建
        p10.add(adminallinformationlabel);
        p10.add(adminadnolabel);
        p10.add(adminadnotext);
        p10.add(adminadnamelabel);
        p10.add(adminadnametext);
        p10.add(adminadpwdlabel);
        p10.add(adminadpwdtext);
        p10.add(adminupdateconfirmbutton);
        p10.add(adminallinformationreturnbutton);
        frame.add(cards);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        CardLayout cl = (CardLayout) (cards.getLayout());
        cl.show(cards, "loginpanel");//调用show()方法显示面板1
        //登录面板响应
        //登录按钮响应
        loginbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                nowusername = usernametext.getText();
                nowuserpassword = String.valueOf(userpasswordtext.getPassword());
                try {
                    Statement studentstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    Statement teacherstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    Statement adminstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    ResultSet studentresult = studentstatement.executeQuery("Select * from student");
                    ResultSet teacherresult = teacherstatement.executeQuery("Select * from teacher");
                    ResultSet adminresult = adminstatement.executeQuery("Select * from admin");
                    while (studentresult.next() && usertype == null) {
                        if (nowusername.equals(studentresult.getString("sno")) && nowuserpassword.equals(studentresult.getString("spwd"))) {
                            studentinformationlabel.setText("当前用户信息：学生" + studentresult.getString("sno") + " " + studentresult.getString("sname"));
                            usertype = "student";
                            loginstudent.setsno(studentresult.getString("sno"));
                            loginstudent.setsname(studentresult.getString("sname"));
                            loginstudent.setssex(studentresult.getString("ssex"));
                            loginstudent.setsage(studentresult.getInt("sage"));
                            loginstudent.setpross(studentresult.getString("pross"));
                            loginstudent.setspwd(studentresult.getString("spwd"));
                            loginstudent.setselectedcourse1(studentresult.getString("selectedcourse1"));
                            loginstudent.setselectedcourse2(studentresult.getString("selectedcourse2"));
                            loginstudent.setselectedcourse3(studentresult.getString("selectedcourse3"));
                            break;
                        }
                    }
                    while (teacherresult.next() && usertype == null) {
                        if (nowusername.equals(teacherresult.getString("tno")) && nowuserpassword.equals(teacherresult.getString("tpwd"))) {
                            teacherinformationlabel.setText("当前用户信息：教师" + teacherresult.getString("tno") + " " + teacherresult.getString("tname"));
                            loginteacher.settno(teacherresult.getString("tno"));
                            loginteacher.settname(teacherresult.getString("tname"));
                            loginteacher.settsex(teacherresult.getString("tsex"));
                            loginteacher.settage(teacherresult.getInt("tage"));
                            loginteacher.settpt(teacherresult.getString("tpt"));
                            loginteacher.settpwd(teacherresult.getString("tpwd"));
                            loginteacher.setteachercourse1(teacherresult.getString("teachercourse1"));
                            loginteacher.setteachercourse2(teacherresult.getString("teachercourse2"));
                            loginteacher.setteachercourse3(teacherresult.getString("teachercourse3"));
                            usertype = "teacher";
                            break;
                        }
                    }
                    while (adminresult.next() && usertype == null) {
                        if (nowusername.equals(adminresult.getString("adno")) && nowuserpassword.equals(adminresult.getString("adpwd"))) {
                            admininformationlabel.setText("当前用户信息：管理员" + adminresult.getString("adno") + " " + adminresult.getString("adname"));
                            loginadmin.setadno(adminresult.getString("adno"));
                            loginadmin.setadname(adminresult.getString("adname"));
                            loginadmin.setadpwd(adminresult.getString("adpwd"));
                            usertype = "admin";
                            break;
                        }
                    }
                    if (usertype == null) {
                        JOptionPane.showMessageDialog(null, "用户名或密码错误！", "错误 ", 0);
                        userpasswordtext.setText("");
                    } else {
                        if (usertype.equals("student")) {
                            studentsnotext.setText(loginstudent.sno);
                            studentsnotext.setEditable(false);
                            studentsnametext.setText(loginstudent.sname);
                            studentssextext.setText(loginstudent.ssex);
                            studentssextext.setEditable(false);
                            studentsagetext.setText(String.valueOf(loginstudent.sage));
                            studentprosstext.setText(loginstudent.pross);
                            studentspwdtext.setText(loginstudent.spwd);
                            JOptionPane.showMessageDialog(null, "登录成功！当前登录身份：学生。", "登录成功 ", JOptionPane.PLAIN_MESSAGE);
                            cl.show(cards, "studentoperationpanel");
                        } else if (usertype.equals("teacher")) {
                            teachertnotext.setText(loginteacher.tno);
                            teachertnotext.setEditable(false);
                            teachertnametext.setText(loginteacher.tname);
                            teachertsextext.setText(loginteacher.tsex);
                            teachertsextext.setEditable(false);
                            teachertagetext.setText(String.valueOf(loginteacher.tage));
                            teachertpttext.setText(loginteacher.tpt);
                            teachertpwdtext.setText(loginteacher.tpwd);
                            JOptionPane.showMessageDialog(null, "登录成功！当前登录身份：教师。", "登录成功 ", JOptionPane.PLAIN_MESSAGE);
                            cl.show(cards, "teacheroperationpanel");
                        } else if (usertype.equals("admin")) {
                            JOptionPane.showMessageDialog(null, "登录成功！当前登录身份：管理员。", "登录成功 ", JOptionPane.PLAIN_MESSAGE);
                            adminadnotext.setText(loginadmin.adno);
                            adminadnotext.setEditable(false);
                            adminadnametext.setText(loginadmin.adname);
                            adminadpwdtext.setText(loginadmin.adpwd);
                            cl.show(cards, "adminoperationpanel");
                        }
                    }
                    studentresult.close();
                    teacherresult.close();
                    adminresult.close();
                    studentstatement.close();
                    teacherstatement.close();
                    adminstatement.close();
                } catch (SQLException sqle) {
                    sqle.printStackTrace();
                }
            }
        });
        //注册按钮响应
        registerbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                cl.show(cards, "regiterpanel");
                usernametext.setText("");
                userpasswordtext.setText("");
            }
        });
        //注册总界面响应
        //返回登录按钮响应
        registergotologinbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                cl.show(cards, "loginpanel");
            }
        });
        //学生注册按钮响应
        studentregisterbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                cl.show(cards, "studentregiterpanel");
            }
        });
        //教师注册按钮响应
        teacherregisterbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                cl.show(cards, "teacherregiterpanel");
            }
        });
        //学生注册界面响应
        //学生确认注册按钮响应
        studentregisterconfirmbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //学号为空
                if (setsnotext.getText().equals("") || setsnotext.getText().equals("请输入用户名（学号）")) {
                    JOptionPane.showMessageDialog(null, "请输入用户名（学号）！！！", "注册失败 ", 0);
                    return;
                }
                //用户名存在检测
                try {
                    Statement studentstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    Statement teacherstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    Statement adminstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    ResultSet studentresult = studentstatement.executeQuery("Select sno from student");
                    ResultSet teacherresult = teacherstatement.executeQuery("Select tno from teacher");
                    ResultSet adminresult = adminstatement.executeQuery("Select adno from admin");
                    //用户名存在处理
                    while (studentresult.next()) {
                        if (setsnotext.getText().equals(studentresult.getString("sno"))) {
                            if (JOptionPane.showConfirmDialog(null, "当前用户名已存在，是否前往登录？", "用户名存在", 0) == 0) {
                                cl.show(cards, "loginpanel");
                                //自动输入当前用户名
                                usernametext.setText(setsnotext.getText());
                                //注册内容全初始化
                                setsnotext.setText("请输入用户名（学号）");
                                setsnametext.setText("请输入姓名");
                                setssexcmobox.setSelectedIndex(0);
                                setsagetext.setText("请输入年龄");
                                setprosstext.setText("请输入专业");
                                setspwdtext.setText("");
                                setspwdconfirmtext.setText("");
                                return;
                            } else {
                                //注册用户名初始化
                                setsnotext.setText("请输入用户名（学号）");
                                return;
                            }
                        }
                    }
                    while (teacherresult.next()) {
                        if (setsnotext.getText().equals(teacherresult.getString("tno"))) {
                            if (JOptionPane.showConfirmDialog(null, "当前用户名已存在，是否前往登录？", "用户名存在", 0) == 0) {
                                cl.show(cards, "loginpanel");
                                //自动输入当前用户名
                                usernametext.setText(setsnotext.getText());
                                //注册内容全初始化
                                setsnotext.setText("请输入用户名（学号）");
                                setsnametext.setText("请输入姓名");
                                setssexcmobox.setSelectedIndex(0);
                                setsagetext.setText("请输入年龄");
                                setprosstext.setText("请输入专业");
                                setspwdtext.setText("");
                                setspwdconfirmtext.setText("");
                                return;
                            } else {
                                //注册用户名初始化
                                setsnotext.setText("请输入用户名（学号）");
                                return;
                            }
                        }
                    }
                    while (adminresult.next()) {
                        if (setsnotext.getText().equals(adminresult.getString("adno"))) {
                            if (JOptionPane.showConfirmDialog(null, "当前用户名已存在，是否前往登录？", "用户名存在", 0) == 0) {
                                cl.show(cards, "loginpanel");
                                //自动输入当前用户名
                                usernametext.setText(setsnotext.getText());
                                //注册内容全初始化
                                setsnotext.setText("请输入用户名（学号）");
                                setsnametext.setText("请输入姓名");
                                setssexcmobox.setSelectedIndex(0);
                                setsagetext.setText("请输入年龄");
                                setprosstext.setText("请输入专业");
                                setspwdtext.setText("");
                                setspwdconfirmtext.setText("");
                                return;
                            } else {
                                //注册用户名初始化
                                setsnotext.setText("请输入用户名（学号）");
                                return;
                            }
                        }
                    }
                    studentresult.close();
                    teacherresult.close();
                    adminresult.close();
                    studentstatement.close();
                    teacherstatement.close();
                    adminstatement.close();
                } catch (SQLException sqle) {
                    sqle.printStackTrace();
                }
                //姓名为空
                if (setsnametext.getText().equals("") || setsnametext.getText().equals("请输入姓名")) {
                    JOptionPane.showMessageDialog(null, "请输入姓名！！！", "注册失败 ", 0);
                    return;
                }
                //性别为空
                if (setssexcmobox.getSelectedIndex() == 0) {
                    JOptionPane.showMessageDialog(null, "请选择性别！！！", "注册失败 ", 0);
                    return;
                }
                //年龄为空
                if (setsagetext.getText().equals("") || setsagetext.getText().equals("请输入年龄")) {
                    JOptionPane.showMessageDialog(null, "请输入年龄！！！", "注册失败 ", 0);
                    return;
                }
                //专业为空
                if (setprosstext.getText().equals("") || setprosstext.getText().equals("请输入专业")) {
                    JOptionPane.showMessageDialog(null, "请输入专业！！！", "注册失败 ", 0);
                    return;
                }
                //密码为空
                if (String.valueOf(setspwdtext.getPassword()).equals("")) {
                    JOptionPane.showMessageDialog(null, "请输入密码！！！", "注册失败 ", 0);
                    return;
                }
                //密码长度不够
                if (setspwdtext.getPassword().length <= 6) {
                    JOptionPane.showMessageDialog(null, "密码强度不够！！！", "注册失败 ", 0);
                    return;
                }
                //确认密码为空
                if (String.valueOf(setspwdconfirmtext.getPassword()).equals("")) {
                    JOptionPane.showMessageDialog(null, "请再次输入密码！！！", "注册失败 ", 0);
                    return;
                }
                //两次密码输入不匹配
                if (!String.valueOf(setspwdtext.getPassword()).equals(String.valueOf(setspwdconfirmtext.getPassword()))) {
                    JOptionPane.showMessageDialog(null, "两次密码输入不匹配！！！", "注册失败 ", 0);
                    return;
                }
                student newstudent = new student();
                newstudent.setsno(setsnotext.getText());
                newstudent.setsname(setsnametext.getText());
                newstudent.setssex(setssexcmobox.getSelectedItem().toString());
                try {
                    newstudent.setsage(Integer.parseInt(setsagetext.getText()));
                } catch (NumberFormatException nfe) {
                    JOptionPane.showMessageDialog(null, "年龄输入非法！！！", "注册失败 ", 0);
                    settagetext.setText("请输入年龄");
                    return;
                }
                newstudent.setpross(setprosstext.getText());
                newstudent.setspwd(String.valueOf(setspwdtext.getPassword()));
                newstudent.add();
                //注册内容全初始化
                setsnotext.setText("请输入用户名（学号）");
                setsnametext.setText("请输入姓名");
                setssexcmobox.setSelectedIndex(0);
                setsagetext.setText("请输入年龄");
                setprosstext.setText("请输入专业");
                setspwdtext.setText("");
                setspwdconfirmtext.setText("");
                //注册成功
                if (JOptionPane.showConfirmDialog(null, "是否返回登录？", "注册成功 ", 0) == 0) {
                    cl.show(cards, "loginpanel");
                }
            }
        });
        //学生注册重选按钮响应
        studentregisterreturnbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //注册内容全初始化
                cl.show(cards, "regiterpanel");
                setsnotext.setText("请输入用户名（学号）");
                setsnametext.setText("请输入姓名");
                setssexcmobox.setSelectedIndex(0);
                setsagetext.setText("请输入年龄");
                setprosstext.setText("请输入专业");
                setspwdtext.setText("");
                setspwdconfirmtext.setText("");
            }
        });
        //教师注册界面响应
        //教师确认注册按钮响应
        teacherregisterconfirmbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //工号为空
                if (settnotext.getText().equals("") || settnotext.getText().equals("请输入用户名（工号）")) {
                    JOptionPane.showMessageDialog(null, "请输入用户名（工号）！！！", "注册失败 ", 0);
                    return;
                }
                //用户名存在检测
                try {
                    Statement studentstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    Statement teacherstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    Statement adminstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    ResultSet studentresult = studentstatement.executeQuery("Select sno from student");
                    ResultSet teacherresult = teacherstatement.executeQuery("Select tno from teacher");
                    ResultSet adminresult = adminstatement.executeQuery("Select adno from admin");
                    //用户名存在处理
                    while (studentresult.next()) {
                        if (settnotext.getText().equals(studentresult.getString("sno"))) {
                            if (JOptionPane.showConfirmDialog(null, "当前用户名已存在，是否前往登录？", "用户名存在", 0) == 0) {
                                cl.show(cards, "loginpanel");
                                //自动输入当前用户名
                                usernametext.setText(settnotext.getText());
                                //注册内容全初始化
                                settnotext.setText("请输入用户名（工号）");
                                settnametext.setText("请输入姓名");
                                settsexcmobox.setSelectedIndex(0);
                                settagetext.setText("请输入年龄");
                                settptcmobox.setSelectedIndex(0);
                                settpwdtext.setText("");
                                settpwdconfirmtext.setText("");
                                return;
                            } else {
                                //注册用户名初始化
                                settnotext.setText("请输入用户名（工号）");
                                return;
                            }
                        }
                    }
                    while (teacherresult.next()) {
                        if (settnotext.getText().equals(teacherresult.getString("tno"))) {
                            if (JOptionPane.showConfirmDialog(null, "当前用户名已存在，是否前往登录？", "用户名存在", 0) == 0) {
                                cl.show(cards, "loginpanel");
                                //自动输入当前用户名
                                usernametext.setText(settnotext.getText());
                                //注册内容全初始化
                                settnotext.setText("请输入用户名（工号）");
                                settnametext.setText("请输入姓名");
                                settsexcmobox.setSelectedIndex(0);
                                settagetext.setText("请输入年龄");
                                settptcmobox.setSelectedIndex(0);
                                settpwdtext.setText("");
                                settpwdconfirmtext.setText("");
                                return;
                            } else {
                                //注册用户名初始化
                                settnotext.setText("请输入用户名（工号）");
                                return;
                            }
                        }
                    }
                    while (adminresult.next()) {
                        if (settnotext.getText().equals(adminresult.getString("adno"))) {
                            if (JOptionPane.showConfirmDialog(null, "当前用户名已存在，是否前往登录？", "用户名存在", 0) == 0) {
                                cl.show(cards, "loginpanel");
                                //自动输入当前用户名
                                usernametext.setText(settnotext.getText());
                                //注册内容全初始化
                                settnotext.setText("请输入用户名（工号）");
                                settnametext.setText("请输入姓名");
                                settsexcmobox.setSelectedIndex(0);
                                settagetext.setText("请输入年龄");
                                settptcmobox.setSelectedIndex(0);
                                settpwdtext.setText("");
                                settpwdconfirmtext.setText("");
                                return;
                            } else {
                                //注册用户名初始化
                                settnotext.setText("请输入用户名（工号）");
                                return;
                            }
                        }
                    }
                    studentresult.close();
                    teacherresult.close();
                    adminresult.close();
                    studentstatement.close();
                    teacherstatement.close();
                    adminstatement.close();
                } catch (SQLException sqle) {
                    sqle.printStackTrace();
                }
                //姓名为空
                if (settnametext.getText().equals("") || settnametext.getText().equals("请输入姓名")) {
                    JOptionPane.showMessageDialog(null, "请输入姓名！！！", "注册失败 ", 0);
                    return;
                }
                //性别为空
                if (settsexcmobox.getSelectedIndex() == 0) {
                    JOptionPane.showMessageDialog(null, "请选择性别！！！", "注册失败 ", 0);
                    return;
                }
                //年龄为空
                if (settagetext.getText().equals("") || settagetext.getText().equals("请输入年龄")) {
                    JOptionPane.showMessageDialog(null, "请输入年龄！！！", "注册失败 ", 0);
                    return;
                }
                //职称为空
                if (settptcmobox.getSelectedIndex() == 0) {
                    JOptionPane.showMessageDialog(null, "请输选择职称！！！", "注册失败 ", 0);
                    return;
                }
                //密码为空
                if (String.valueOf(settpwdtext.getPassword()).equals("")) {
                    JOptionPane.showMessageDialog(null, "请输入密码！！！", "注册失败 ", 0);
                    return;
                }
                //密码长度不够
                if (settpwdtext.getPassword().length <= 6) {
                    JOptionPane.showMessageDialog(null, "密码强度不够！！！", "注册失败 ", 0);
                    return;
                }
                //确认密码为空
                if (String.valueOf(settpwdconfirmtext.getPassword()).equals("")) {
                    JOptionPane.showMessageDialog(null, "请再次输入密码！！！", "注册失败 ", 0);
                    return;
                }
                //两次密码输入不匹配
                if (!String.valueOf(settpwdtext.getPassword()).equals(String.valueOf(settpwdconfirmtext.getPassword()))) {
                    JOptionPane.showMessageDialog(null, "两次密码输入不匹配！！！", "注册失败 ", 0);
                    return;
                }
                teacher newteacher = new teacher();
                newteacher.settno(settnotext.getText());
                newteacher.settname(settnametext.getText());
                newteacher.settsex(settsexcmobox.getSelectedItem().toString());
                try {
                    newteacher.settage(Integer.parseInt(settagetext.getText()));
                } catch (NumberFormatException nfe) {
                    JOptionPane.showMessageDialog(null, "年龄输入非法！！！", "注册失败 ", 0);
                    settagetext.setText("请输入年龄");
                    return;
                }
                newteacher.settpt(settptcmobox.getSelectedItem().toString());
                newteacher.settpwd(String.valueOf(setspwdtext.getPassword()));
                newteacher.add();
                //注册内容全初始化
                settnotext.setText("请输入用户名（工号）");
                settnametext.setText("请输入姓名");
                settsexcmobox.setSelectedIndex(0);
                settagetext.setText("请输入年龄");
                settptcmobox.setSelectedIndex(0);
                settpwdtext.setText("");
                settpwdconfirmtext.setText("");
                //注册成功
                if (JOptionPane.showConfirmDialog(null, "是否返回登录？", "注册成功 ", 0) == 0) {
                    cl.show(cards, "loginpanel");
                }
            }
        });
        //教师注册重选按钮响应
        teacherregisterreturnbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                cl.show(cards, "regiterpanel");
                settnotext.setText("请输入用户名（工号）");
                settnametext.setText("请输入姓名");
                settsexcmobox.setSelectedIndex(0);
                settagetext.setText("请输入年龄");
                settptcmobox.setSelectedIndex(0);
                settpwdtext.setText("");
                settpwdconfirmtext.setText("");
            }
        });
        //学生操作界面响应
        //学生退出登录按钮响应
        studentquitbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (JOptionPane.showConfirmDialog(null, "是否退出登录？", "退出登录 ", 0) == 0) {
                    cl.show(cards, "loginpanel");
                    usertype = null;
                    nowusername = "";
                    nowuserpassword = "";
                    //登录界面初始化
                    usernametext.setText("");
                    userpasswordtext.setText("");
                }
            }
        });
        //学生查询课程按钮响应
        studentfindcoursebutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (studentfindcoursecombobox.getSelectedIndex() != 0 && studentfindcoursecombobox.getSelectedIndex() < 5 && (studentfindkeytext.getText().equals("请输入课程查询的关键字") || studentfindkeytext.getText().equals(""))) {
                    JOptionPane.showMessageDialog(null, "请输入关键字！！！", "查询失败 ", 0);
                    return;
                }
                String studentfindsql = null;
                String numberofstudentfindsql = null;
                switch (studentfindcoursecombobox.getSelectedIndex()) {
                    case 0: {
                        studentfindsql = "select * from course";
                        numberofstudentfindsql = "select count(*) from course";
                        break;
                    }
                    case 1: {
                        studentfindsql = "select * from course where cno like '%" + studentfindkeytext.getText() + "%'";
                        numberofstudentfindsql = "select count(*) from course where cno like '%" + studentfindkeytext.getText() + "%'";
                        break;
                    }
                    case 2: {
                        studentfindsql = "select * from course where cname like '%" + studentfindkeytext.getText() + "%'";
                        numberofstudentfindsql = "select count(*) from course where cname like '%" + studentfindkeytext.getText() + "%'";
                        break;
                    }
                    case 3: {
                        studentfindsql = "select * from course where cteacher like '%" + studentfindkeytext.getText() + "%'";
                        numberofstudentfindsql = "select count(*) from course where cteacher like '%" + studentfindkeytext.getText() + "%'";
                        break;
                    }
                    case 4: {
                        studentfindsql = "select * from course where credit like '%" + studentfindkeytext.getText() + "%'";
                        numberofstudentfindsql = "select count(*) from course where credit like '%" + studentfindkeytext.getText() + "%'";
                        break;
                    }
                    case 5: {
                        studentfindsql = "select * from course where cno='" + loginstudent.getselectedcourse1() + "' or cno='" + loginstudent.getselectedcourse2() + "' or cno='" + loginstudent.getselectedcourse3() + "'";
                        numberofstudentfindsql = "select count(*) from course where cno='" + loginstudent.getselectedcourse1() + "' or cno='" + loginstudent.getselectedcourse2() + "' or cno='" + loginstudent.getselectedcourse3() + "'";
                        break;
                    }
                    case 6: {
                        studentfindsql = "select * from course where capacity != '0'";
                        numberofstudentfindsql = "select count(*) from course where capacity != '0'";
                        break;
                    }
                }
                try {
                    Statement findcoursestatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    Statement numberoffindcoursestatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    ResultSet findcourseresult = findcoursestatement.executeQuery(studentfindsql);
                    ResultSet numberoffindcourseresult = numberoffindcoursestatement.executeQuery(numberofstudentfindsql);
                    numberoffindcourseresult.next();
                    if (numberoffindcourseresult.getInt("count(*)") == 0) {
                        JOptionPane.showMessageDialog(null, "无查询结果！！！", "无查询结果 ", 0);
                        return;
                    }
                    for (i = 0; findcourseresult.next(); i++) {
                        courseresult[i].setcno(findcourseresult.getString("cno"));
                        courseresult[i].setcname(findcourseresult.getString("cname"));
                        courseresult[i].setcteacher(findcourseresult.getString("cteacher"));
                        courseresult[i].setctno(findcourseresult.getString("ctno"));
                        courseresult[i].setcredit(findcourseresult.getInt("credit"));
                        courseresult[i].setcapacity(findcourseresult.getInt("capacity"));
                        str = courseresult[i].getcno() + "     " + courseresult[i].getcname() + "    " + courseresult[i].getcteacher() + "     " + courseresult[i].getcredit() + "     " + courseresult[i].getcapacity();
                        resultvector.addElement(str);
                    }
                    Object[] courseresultobject = resultvector.toArray();
                    courselist.setListData(courseresultobject);
                    resultvector.clear();
                    findcoursestatement.close();
                    numberoffindcoursestatement.close();
                    findcourseresult.close();
                    numberoffindcourseresult.close();
                } catch (SQLException sqle) {
                    sqle.printStackTrace();
                }
            }
        });
        //学生选课按钮响应
        studentselectcoursebutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (courselist.getSelectedIndex() == -1) {
                    JOptionPane.showMessageDialog(null, "未选中选项！！！", "错误 ", 0);
                    return;
                }
                cselect cs = new cselect();
                cs.cno = courseresult[courselist.getSelectedIndex()].cno;
                cs.cname = courseresult[courselist.getSelectedIndex()].cname;
                cs.sno = loginstudent.sno;
                cs.sname = loginstudent.sname;
                cs.tno = courseresult[courselist.getSelectedIndex()].ctno;
                cs.tname = courseresult[courselist.getSelectedIndex()].cteacher;
                if (loginstudent.selectedcourse1 == courseresult[courselist.getSelectedIndex()].cno || loginstudent.selectedcourse2 == courseresult[courselist.getSelectedIndex()].cno || loginstudent.selectedcourse3 == courseresult[courselist.getSelectedIndex()].cno) {
                    JOptionPane.showMessageDialog(null, "该课程已经选择，无法重复选课！！！", "选课失败 ", 0);
                    return;
                }
                if (loginstudent.selectedcourse1 == null) {
                    loginstudent.selectedcourse1 = courseresult[courselist.getSelectedIndex()].cno;
                    loginstudent.updatecourse();
                    cs.add();
                    return;
                }
                if (loginstudent.selectedcourse2 == null) {
                    loginstudent.selectedcourse2 = courseresult[courselist.getSelectedIndex()].cno;
                    loginstudent.updatecourse();
                    cs.add();
                    return;
                }
                if (loginstudent.selectedcourse3 == null) {
                    loginstudent.selectedcourse3 = courseresult[courselist.getSelectedIndex()].cno;
                    loginstudent.updatecourse();
                    cs.add();
                    return;
                }
                JOptionPane.showMessageDialog(null, "选课已满！！！", "选课失败 ", 0);
            }
        });
        //学生退课按钮响应
        studentdeletecoursebutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (courselist.getSelectedIndex() == -1) {
                    JOptionPane.showMessageDialog(null, "未选中选项！！！", "错误 ", 0);
                    return;
                }
                cselect cs = new cselect();
                cs.sno = loginstudent.sno;
                cs.cno = courseresult[courselist.getSelectedIndex()].cno;
                cs.tno = courseresult[courselist.getSelectedIndex()].ctno;
                switch (courselist.getSelectedIndex()) {
                    case 0:
                        loginstudent.selectedcourse1 = null;
                    case 1:
                        loginstudent.selectedcourse2 = null;
                    case 2:
                        loginstudent.selectedcourse3 = null;
                }
                loginstudent.updatecourse();
                cs.delete();
            }
        });
        //学生个人信息按钮响应
        studentprivateinformationbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                cl.show(cards, "studentinformationpanel");
            }
        });
        //学生个人信息界面响应
        //更改按钮响应
        studentupdateconfirmbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //更新个人信息
                loginstudent.sno = studentsnotext.getText();
                loginstudent.sname = studentsnametext.getText();
                loginstudent.ssex = studentssextext.getText();
                try {
                    loginstudent.sage = Integer.parseInt(studentsagetext.getText());
                } catch (NumberFormatException nfe) {
                    JOptionPane.showMessageDialog(null, "年龄输入非法！！！", "更改失败 ", 0);
                    studentsagetext.setText("请输入年龄");
                    return;
                }
                loginstudent.pross = studentprosstext.getText();
                loginstudent.spwd = studentspwdtext.getText();
                loginstudent.update();
                JOptionPane.showMessageDialog(null, "个人信息更改成功", "提示", JOptionPane.PLAIN_MESSAGE);
            }
        });
        //返回按钮响应
        studentallinformationreturnbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (loginstudent.sno.equals(studentsnotext.getText()) && loginstudent.sname.equals(studentsnametext.getText()) && loginstudent.ssex.equals(studentssextext.getText()) && String.valueOf(loginstudent.sage).equals(studentsagetext.getText()) && loginstudent.pross.equals(studentprosstext.getText()) && loginstudent.spwd.equals(studentspwdtext.getText())) {
                    cl.show(cards, "studentoperationpanel");
                } else {
                    if (JOptionPane.showConfirmDialog(null, "是否保存更改？", "个人信息已改变", 0) == 0) {
                        //更新个人信息
                        loginstudent.sno = studentsnotext.getText();
                        loginstudent.sname = studentsnametext.getText();
                        loginstudent.ssex = studentssextext.getText();
                        try {
                            loginstudent.sage = Integer.parseInt(studentsagetext.getText());
                        } catch (NumberFormatException nfe) {
                            JOptionPane.showMessageDialog(null, "年龄输入非法！！！", "更改失败 ", 0);
                            studentsagetext.setText("请输入年龄");
                            return;
                        }
                        loginstudent.pross = studentprosstext.getText();
                        loginstudent.spwd = studentspwdtext.getText();
                        loginstudent.update();
                        JOptionPane.showMessageDialog(null, "个人信息更改成功", "提示", JOptionPane.PLAIN_MESSAGE);
                    } else {
                        studentsnotext.setText(loginstudent.sno);
                        studentsnametext.setText(loginstudent.sname);
                        studentssextext.setText(loginstudent.ssex);
                        studentsagetext.setText(String.valueOf(loginstudent.sage));
                        studentprosstext.setText(loginstudent.pross);
                        studentspwdtext.setText(loginstudent.spwd);
                    }
                    cl.show(cards, "studentoperationpanel");
                }
            }
        });
        //教师操作界面响应
        //教师退出登录按钮响应
        teacherquitbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (JOptionPane.showConfirmDialog(null, "是否退出登录？", "退出登录 ", 0) == 0) {
                    cl.show(cards, "loginpanel");
                    usertype = null;
                    nowusername = "";
                    nowuserpassword = "";
                    //登录界面初始化
                    usernametext.setText("");
                    userpasswordtext.setText("");
                }
            }
        });
        //教师个人信息按钮响应
        teacherprivateinfomationbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                cl.show(cards, "teacherinformationpanel");
            }
        });
        //教师个人信息界面响应
        //更改按钮响应
        teacherupdateconfirmbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //更新个人信息
                loginteacher.tno = teachertnotext.getText();
                loginteacher.tname = teachertnametext.getText();
                loginteacher.tsex = teachertsextext.getText();
                try {
                    loginteacher.tage = Integer.parseInt(teachertagetext.getText());
                } catch (NumberFormatException nfe) {
                    JOptionPane.showMessageDialog(null, "年龄输入非法！！！", "更改失败 ", 0);
                    teachertagetext.setText("请输入年龄");
                    return;
                }
                loginteacher.tpt = teachertpttext.getText();
                loginteacher.tpwd = teachertpwdtext.getText();
                loginteacher.update();
                JOptionPane.showMessageDialog(null, "个人信息更改成功", "提示", JOptionPane.PLAIN_MESSAGE);
            }
        });
        //返回按钮响应
        teacherallinformationreturnbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (loginteacher.tno.equals(teachertnotext.getText()) && loginteacher.tname.equals(teachertnametext.getText()) && loginteacher.tsex.equals(teachertsextext.getText()) && String.valueOf(loginteacher.tage).equals(teachertagetext.getText()) && loginteacher.tpt.equals(teachertpttext.getText()) && loginteacher.tpwd.equals(teachertpwdtext.getText())) {
                    cl.show(cards, "teacheroperationpanel");
                } else {
                    if (JOptionPane.showConfirmDialog(null, "是否保存更改？", "个人信息已改变", 0) == 0) {
                        //更新个人信息
                        loginteacher.tno = teachertnotext.getText();
                        loginteacher.tname = teachertnametext.getText();
                        loginteacher.tsex = teachertsextext.getText();
                        try {
                            loginteacher.tage = Integer.parseInt(teachertagetext.getText());
                        } catch (NumberFormatException nfe) {
                            JOptionPane.showMessageDialog(null, "年龄输入非法！！！", "更改失败 ", 0);
                            teachertagetext.setText("请输入年龄");
                            return;
                        }
                        loginteacher.tpt = teachertpttext.getText();
                        loginteacher.tpwd = teachertpwdtext.getText();
                        loginteacher.update();
                        JOptionPane.showMessageDialog(null, "个人信息更改成功", "提示", JOptionPane.PLAIN_MESSAGE);
                    } else {
                        teachertnotext.setText(loginteacher.tno);
                        teachertnametext.setText(loginteacher.tname);
                        teachertsextext.setText(loginteacher.tsex);
                        teachertagetext.setText(String.valueOf(loginteacher.tage));
                        teachertpttext.setText(loginteacher.tpt);
                        teachertpwdtext.setText(loginteacher.tpwd);
                    }
                }
                cl.show(cards, "teacheroperationpanel");
            }
        });
        //教师添加课程按钮响应
        teacheraddcoursebutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                cl.show(cards, "teacheraddcoursepanel");
            }
        });
        //教师添加课程界面响应
        //添加课程界面返回按钮
        teacheraddcoursereturnbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                cl.show(cards, "teacheroperationpanel");
                setcnotext.setText("请输入课程号");
                setcnametext.setText("请输入课程名");
                setcredittext.setText("请输入课程学分");
                setcapacitytext.setText("请输入课程容量");
            }
        });
        //课程添加确认按钮
        courseregisterconfirmbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //课程号为空
                if (setcnotext.getText().equals("") || setcnotext.getText().equals("请输入课程号")) {
                    JOptionPane.showMessageDialog(null, "请输入课程号！！！", "课程添加失败", 0);
                    return;
                }
                try {
                    Statement coursestatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    ResultSet courseresult = coursestatement.executeQuery("Select cno from course");
                    //课程号存在处理
                    while (courseresult.next()) {
                        if (setcnotext.getText().equals(courseresult.getString("cno"))) {
                            JOptionPane.showMessageDialog(null, "课程号已经存在！！！", "课程添加失败", 0);
                            setcnotext.setText("请输入课程号");
                            return;
                        }
                    }
                    coursestatement.close();
                    courseresult.close();
                } catch (SQLException sqle) {
                    sqle.printStackTrace();
                }
                //课程名为空
                if (setcnametext.getText().equals("") || setcnametext.getText().equals("请输入课程名")) {
                    JOptionPane.showMessageDialog(null, "请输入课程名！！！", "课程添加失败", 0);
                    return;
                }
                //课程学分为空
                if (setcredittext.getText().equals("") || setcredittext.getText().equals("请输入课程学分")) {
                    JOptionPane.showMessageDialog(null, "请输入课程号！！！", "课程添加失败", 0);
                    return;
                }
                //课程容量为空
                if (setcapacitytext.getText().equals("") || setcapacitytext.getText().equals("请输入课程容量")) {
                    JOptionPane.showMessageDialog(null, "请输入课程号！！！", "课程添加失败", 0);
                    return;
                }
                course newcourse = new course();
                newcourse.setcno(setcnotext.getText());
                newcourse.setcname(setcnametext.getText());
                newcourse.setcteacher(loginteacher.tname);
                newcourse.setctno(loginteacher.tno);
                try {
                    newcourse.setcredit(Integer.parseInt(setcredittext.getText()));
                } catch (NumberFormatException nfe) {
                    JOptionPane.showMessageDialog(null, "课程学分输入非法！！！", "课程添加失败", 0);
                    setcredittext.setText("请输入课程学分");
                    return;
                }
                try {
                    newcourse.setcapacity(Integer.parseInt(setcapacitytext.getText()));
                } catch (NumberFormatException nfe) {
                    JOptionPane.showMessageDialog(null, "课程容量输入非法！！！", "课程添加失败", 0);
                    setcapacitytext.setText("请输入课程容量");
                    return;
                }
                newcourse.add();
                if (JOptionPane.showConfirmDialog(null, "是否继续添加课程", "课程添加成功 ", 0) == 0) {
                }else{
                    cl.show(cards, "teacheroperationpanel");
                }
            }
        });
        //教师查询学生按钮
        teacherfindstudentbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String findsql = "SELECT * FROM student WHERE selectedcourse1='"+loginteacher.teachercourse1+"' or selectedcourse1='"+loginteacher.teachercourse2+"' or selectedcourse1='"+loginteacher.teachercourse3+"' or selectedcourse2='"+loginteacher.teachercourse1+"' or selectedcourse2='"+loginteacher.teachercourse2+"' or selectedcourse2='"+loginteacher.teachercourse3+"' or selectedcourse3='"+loginteacher.teachercourse1+"' or selectedcourse3='"+loginteacher.teachercourse2+"' or selectedcourse3='"+loginteacher.teachercourse3+"'";
                String numberoffindsql="SELECT count(*) FROM student WHERE selectedcourse1='"+loginteacher.teachercourse1+"' or selectedcourse1='"+loginteacher.teachercourse2+"' or selectedcourse1='"+loginteacher.teachercourse3+"' or selectedcourse2='"+loginteacher.teachercourse1+"' or selectedcourse2='"+loginteacher.teachercourse2+"' or selectedcourse2='"+loginteacher.teachercourse3+"' or selectedcourse3='"+loginteacher.teachercourse1+"' or selectedcourse3='"+loginteacher.teachercourse2+"' or selectedcourse3='"+loginteacher.teachercourse3+"'";
                try {
                    Statement findstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    Statement numberoffindstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    ResultSet findresult = findstatement.executeQuery(findsql);
                    ResultSet numberoffindresult = numberoffindstatement.executeQuery(numberoffindsql);
                    numberoffindresult.next();
                    if (numberoffindresult.getInt("count(*)") == 0) {
                        JOptionPane.showMessageDialog(null, "无查询结果！！！", "无查询结果 ", 0);
                        return;
                    }
                    for (i = 0; findresult.next(); i++) {
                        studentresult[i].setsno(findresult.getString("sno"));
                        studentresult[i].setsname(findresult.getString("sname"));
                        studentresult[i].setssex(findresult.getString("ssex"));
                        studentresult[i].setsage(Integer.parseInt(findresult.getString("sage")));
                        studentresult[i].setpross(findresult.getString("pross"));
                        studentresult[i].setspwd(findresult.getString("spwd"));
                        str = studentresult[i].getsno() + "     " + studentresult[i].getsname() + "    " + studentresult[i].getssex() + "     " + studentresult[i].getsage() + "     " + studentresult[i].getpross() + "     " + studentresult[i].getspwd();
                        resultvector.addElement(str);
                    }
                    Object[] courseresultobject = resultvector.toArray();
                    teacherselectlist.setListData(courseresultobject);
                    resultvector.clear();
                    findstatement.close();
                    numberoffindstatement.close();
                    findresult.close();
                    numberoffindresult.close();
                } catch (SQLException sqle) {
                    sqle.printStackTrace();
                }
            }
        });
        //管理员信息界面
        //管理员信息按钮
        adminprivateinformationbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                cl.show(cards, "admininformationpanel");
            }
        });
        //管理员信息更改按钮
        adminupdateconfirmbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //更新个人信息
                loginadmin.adno = adminadnotext.getText();
                loginadmin.adname = adminadnametext.getText();
                loginadmin.adpwd = adminadpwdtext.getText();
                loginadmin.update();
                JOptionPane.showMessageDialog(null, "个人信息更改成功", "提示", JOptionPane.PLAIN_MESSAGE);
            }
        });
        //管理员信息返回按钮
        adminallinformationreturnbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (loginadmin.adno.equals(adminadnotext.getText()) && loginadmin.adname.equals(adminadnametext.getText()) && loginadmin.adpwd.equals(adminadpwdtext.getText())) {
                    cl.show(cards, "adminoperationpanel");
                } else {
                    if (JOptionPane.showConfirmDialog(null, "是否保存更改？", "个人信息已改变", 0) == 0) {
                        //更新个人信息
                        loginadmin.adno = adminadnotext.getText();
                        loginadmin.adname = adminadnametext.getText();
                        loginadmin.adpwd = adminadpwdtext.getText();
                        loginadmin.update();
                        JOptionPane.showMessageDialog(null, "个人信息更改成功", "提示", JOptionPane.PLAIN_MESSAGE);
                    } else {
                        adminadnotext.setText(loginadmin.adno);
                        adminadnametext.setText(loginadmin.adname);
                        adminadpwdtext.setText(loginadmin.adpwd);
                    }
                }
                cl.show(cards, "adminoperationpanel");
            }
        });
        //管理员操作界面响应
        //管理员查询学生按钮响应
        adminfindstudentbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                flag = 0;
                if (adminfindstudentcombobox.getSelectedIndex() != 0 && adminfindstudentcombobox.getSelectedIndex() < 4 && (adminfindkeytext.getText().equals("请输入查询的关键字") || adminfindkeytext.getText().equals(""))) {
                    JOptionPane.showMessageDialog(null, "请输入关键字！！！", "查询失败 ", 0);
                    return;
                }
                String findsql = null;
                String numberoffindsql = null;
                switch (adminfindstudentcombobox.getSelectedIndex()) {
                    case 0: {
                        findsql = "select * from student";
                        numberoffindsql = "select count(*) from course";
                        break;
                    }
                    case 1: {
                        findsql = "select * from student where sno like '%" + adminfindkeytext.getText() + "%'";
                        numberoffindsql = "select count(*) from student where sno like '%" + adminfindkeytext.getText() + "%'";
                        break;
                    }
                    case 2: {
                        findsql = "select * from student where sname like '%" + adminfindkeytext.getText() + "%'";
                        numberoffindsql = "select count(*) from student where sname like '%" + adminfindkeytext.getText() + "%'";
                        break;
                    }
                    case 3: {
                        findsql = "select * from student where pross like '%" + adminfindkeytext.getText() + "%'";
                        numberoffindsql = "select count(*) from student where pross like '%" + adminfindkeytext.getText() + "%'";
                        break;
                    }
                }
                try {
                    Statement findstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    Statement numberoffindstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    ResultSet findresult = findstatement.executeQuery(findsql);
                    ResultSet numberoffindresult = numberoffindstatement.executeQuery(numberoffindsql);
                    numberoffindresult.next();
                    if (numberoffindresult.getInt("count(*)") == 0) {
                        JOptionPane.showMessageDialog(null, "无查询结果！！！", "无查询结果 ", 0);
                        return;
                    }
                    for (i = 0; findresult.next(); i++) {
                        studentresult[i].setsno(findresult.getString("sno"));
                        studentresult[i].setsname(findresult.getString("sname"));
                        studentresult[i].setssex(findresult.getString("ssex"));
                        studentresult[i].setsage(Integer.parseInt(findresult.getString("sage")));
                        studentresult[i].setpross(findresult.getString("pross"));
                        studentresult[i].setspwd(findresult.getString("spwd"));
                        str = studentresult[i].getsno() + "     " + studentresult[i].getsname() + "    " + studentresult[i].getssex() + "     " + studentresult[i].getsage() + "     " + studentresult[i].getpross() + "     " + studentresult[i].getspwd();
                        resultvector.addElement(str);
                    }
                    Object[] courseresultobject = resultvector.toArray();
                    adminselectlist.setListData(courseresultobject);
                    resultvector.clear();
                    findstatement.close();
                    numberoffindstatement.close();
                    findresult.close();
                    numberoffindresult.close();
                } catch (SQLException sqle) {
                    sqle.printStackTrace();
                }
            }
        });
        //管理员查询教师按钮响应
        adminfindteacherbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                flag = 1;
                if (adminfindstudentcombobox.getSelectedIndex() != 0 && adminfindstudentcombobox.getSelectedIndex() < 4 && (adminfindkeytext.getText().equals("请输入查询的关键字") || adminfindkeytext.getText().equals(""))) {
                    JOptionPane.showMessageDialog(null, "请输入关键字！！！", "查询失败 ", 0);
                    return;
                }
                String findsql = null;
                String numberoffindsql = null;
                switch (adminfindstudentcombobox.getSelectedIndex()) {
                    case 0: {
                        findsql = "select * from teacher";
                        numberoffindsql = "select count(*) from teacher";
                        break;
                    }
                    case 1: {
                        findsql = "select * from teacher where tno like '%" + adminfindkeytext.getText() + "%'";
                        numberoffindsql = "select count(*) from teacher where tno like '%" + adminfindkeytext.getText() + "%'";
                        break;
                    }
                    case 2: {
                        findsql = "select * from teacher where tname like '%" + adminfindkeytext.getText() + "%'";
                        numberoffindsql = "select count(*) from teacher where tname like '%" + adminfindkeytext.getText() + "%'";
                        break;
                    }
                    case 3: {
                        findsql = "select * from teacher where tpt like '%" + adminfindkeytext.getText() + "%'";
                        numberoffindsql = "select count(*) from teacher where tpt like '%" + adminfindkeytext.getText() + "%'";
                        break;
                    }
                }
                try {
                    Statement findstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    Statement numberoffindstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    ResultSet findresult = findstatement.executeQuery(findsql);
                    ResultSet numberoffindresult = numberoffindstatement.executeQuery(numberoffindsql);
                    numberoffindresult.next();
                    if (numberoffindresult.getInt("count(*)") == 0) {
                        JOptionPane.showMessageDialog(null, "无查询结果！！！", "无查询结果 ", 0);
                        return;
                    }
                    for (i = 0; findresult.next(); i++) {
                        teacherresult[i].settno(findresult.getString("tno"));
                        teacherresult[i].settname(findresult.getString("tname"));
                        teacherresult[i].settsex(findresult.getString("tsex"));
                        teacherresult[i].settage(Integer.parseInt(findresult.getString("tage")));
                        teacherresult[i].settpt(findresult.getString("tpt"));
                        teacherresult[i].settpwd(findresult.getString("tpwd"));
                        str = teacherresult[i].gettno() + "     " + teacherresult[i].gettname() + "    " + teacherresult[i].gettsex() + "     " + teacherresult[i].gettage() + "     " + teacherresult[i].gettpt() + "     " + teacherresult[i].gettpwd();
                        resultvector.addElement(str);
                    }
                    Object[] courseresultobject = resultvector.toArray();
                    adminselectlist.setListData(courseresultobject);
                    resultvector.clear();
                    findstatement.close();
                    numberoffindstatement.close();
                    findresult.close();
                    numberoffindresult.close();
                } catch (SQLException sqle) {
                    sqle.printStackTrace();
                }
            }
        });
        //管理员查询课程按钮响应
        adminfindcoursebutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                flag = 2;
                if (adminfindcoursecombobox.getSelectedIndex() != 0 && adminfindcoursecombobox.getSelectedIndex() < 5 && (adminfindkeytext.getText().equals("请输入查询的关键字") || adminfindkeytext.getText().equals(""))) {
                    JOptionPane.showMessageDialog(null, "请输入关键字！！！", "查询失败 ", 0);
                    return;
                }
                String findsql = null;
                String numberoffindsql = null;
                switch (adminfindcoursecombobox.getSelectedIndex()) {
                    case 0: {
                        findsql = "select * from course";
                        numberoffindsql = "select count(*) from course";
                        break;
                    }
                    case 1: {
                        findsql = "select * from course where cno like '%" + adminfindkeytext.getText() + "%'";
                        numberoffindsql = "select count(*) from course where cno like '%" + adminfindkeytext.getText() + "%'";
                        break;
                    }
                    case 2: {
                        findsql = "select * from course where cname like '%" + adminfindkeytext.getText() + "%'";
                        numberoffindsql = "select count(*) from course where cname like '%" + adminfindkeytext.getText() + "%'";
                        break;
                    }
                    case 3: {
                        findsql = "select * from course where cteacher like '%" + adminfindkeytext.getText() + "%'";
                        numberoffindsql = "select count(*) from course where cteacher like '%" + adminfindkeytext.getText() + "%'";
                        break;
                    }
                    case 4: {
                        findsql = "select * from course where credit like '%" + adminfindkeytext.getText() + "%'";
                        numberoffindsql = "select count(*) from course where credit like '%" + adminfindkeytext.getText() + "%'";
                        break;
                    }
                }
                try {
                    Statement findstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    Statement numberoffindstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    ResultSet findresult = findstatement.executeQuery(findsql);
                    ResultSet numberoffindresult = numberoffindstatement.executeQuery(numberoffindsql);
                    numberoffindresult.next();
                    if (numberoffindresult.getInt("count(*)") == 0) {
                        JOptionPane.showMessageDialog(null, "无查询结果！！！", "无查询结果 ", 0);
                        return;
                    }
                    for (i = 0; findresult.next(); i++) {
                        courseresult[i].setcno(findresult.getString("cno"));
                        courseresult[i].setcname(findresult.getString("cname"));
                        courseresult[i].setcteacher(findresult.getString("cteacher"));
                        courseresult[i].setctno(findresult.getString("ctno"));
                        courseresult[i].setcredit(findresult.getInt("credit"));
                        courseresult[i].setcapacity(findresult.getInt("capacity"));
                        str = courseresult[i].getcno() + "     " + courseresult[i].getcname() + "    " + courseresult[i].getcteacher() + "     " + courseresult[i].getcredit() + "     " + courseresult[i].getcapacity();
                        resultvector.addElement(str);
                    }
                    Object[] courseresultobject = resultvector.toArray();
                    adminselectlist.setListData(courseresultobject);
                    resultvector.clear();
                    findstatement.close();
                    numberoffindstatement.close();
                    findresult.close();
                    numberoffindresult.close();
                } catch (SQLException sqle) {
                    sqle.printStackTrace();
                }
            }
        });
        //管理员查询选课按钮响应
        adminfindcselectbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                flag = 3;
                if (adminfindstudentcombobox.getSelectedIndex() != 0 && adminfindstudentcombobox.getSelectedIndex() < 3 && (adminfindkeytext.getText().equals("请输入查询的关键字") || adminfindkeytext.getText().equals(""))) {
                    JOptionPane.showMessageDialog(null, "请输入关键字！！！", "查询失败 ", 0);
                    return;
                }
                String findsql = null;
                String numberoffindsql = null;
                switch (adminfindstudentcombobox.getSelectedIndex()) {
                    case 0: {
                        findsql = "select * from cselect";
                        numberoffindsql = "select count(*) from cselect";
                        break;
                    }
                    case 1: {
                        findsql = "select * from cselect where cno like '%" + adminfindkeytext.getText() + "%'";
                        numberoffindsql = "select count(*) from cselect where tno like '%" + adminfindkeytext.getText() + "%'";
                        break;
                    }
                    case 2: {
                        findsql = "select * from cselect where sno like '%" + adminfindkeytext.getText() + "%'";
                        numberoffindsql = "select count(*) from cselect where tname like '%" + adminfindkeytext.getText() + "%'";
                        break;
                    }
                    case 3: {
                        findsql = "select * from cselect where tno like '%" + adminfindkeytext.getText() + "%'";
                        numberoffindsql = "select count(*) from cselect where tpt like '%" + adminfindkeytext.getText() + "%'";
                        break;
                    }
                }
                try {
                    Statement findstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    Statement numberoffindstatement = sqlcnt.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    ResultSet findresult = findstatement.executeQuery(findsql);
                    ResultSet numberoffindresult = numberoffindstatement.executeQuery(numberoffindsql);
                    numberoffindresult.next();
                    if (numberoffindresult.getInt("count(*)") == 0) {
                        JOptionPane.showMessageDialog(null, "无查询结果！！！", "无查询结果 ", 0);
                        return;
                    }
                    for (i = 0; findresult.next(); i++) {
                        csresult[i].setcno(findresult.getString("cno"));
                        csresult[i].setcname(findresult.getString("cname"));
                        csresult[i].setsno(findresult.getString("sno"));
                        csresult[i].setsname(findresult.getString("sname"));
                        csresult[i].settno(findresult.getString("tno"));
                        csresult[i].settname(findresult.getString("tname"));
                        str = csresult[i].getcno() + "     " + csresult[i].getcname() + "    " + csresult[i].getsno() + "     " + csresult[i].getsname() + "     " + csresult[i].gettno() + "     " + csresult[i].gettname();
                        resultvector.addElement(str);
                    }
                    Object[] csresultobject = resultvector.toArray();
                    adminselectlist.setListData(csresultobject);
                    resultvector.clear();
                    findstatement.close();
                    numberoffindstatement.close();
                    findresult.close();
                    numberoffindresult.close();
                } catch (SQLException sqle) {
                    sqle.printStackTrace();
                }
            }
        });
        //管理员删除记录按钮响应
        admindeleterbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (adminselectlist.getSelectedIndex() == -1) {
                    JOptionPane.showMessageDialog(null, "未选中选项！！！", "错误 ", 0);
                    return;
                }
                if (JOptionPane.showConfirmDialog(null, "是否删除？", "删除记录", 0) == 0) {
                    switch (flag) {
                        case 0:
                            studentresult[adminselectlist.getSelectedIndex()].delete();
                            break;
                        case 1:
                            teacherresult[adminselectlist.getSelectedIndex()].delete();
                            break;
                        case 2:
                            courseresult[adminselectlist.getSelectedIndex()].delete();
                            break;
                        case 3:
                            csresult[adminselectlist.getSelectedIndex()].delete();
                            break;
                    }
                }
            }
        });
        //管理员通过注册按钮响应
        //管理员退出登录按钮响应
        adminquitbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (JOptionPane.showConfirmDialog(null, "是否退出登录？", "退出登录 ", 0) == 0) {
                    cl.show(cards, "loginpanel");
                    usertype = null;
                    nowusername = "";
                    nowuserpassword = "";
                    //登录界面初始化
                    usernametext.setText("");
                    userpasswordtext.setText("");
                }
            }
        });
    }
}

class student {
    int i;
    //学生信息
    String sno = "";
    String sname;
    String ssex;
    int sage;
    String pross;//专业
    String selectedcourse1;
    String selectedcourse2;
    String selectedcourse3;
    String spwd;

    //学生方法
    //设置变量
    void setsno(String str) {
        sno = str;
    }

    void setsname(String str) {
        sname = str;
    }

    void setssex(String str) {
        ssex = str;
    }

    void setsage(int x) {
        sage = x;
    }

    void setpross(String str) {
        pross = str;
    }

    void setselectedcourse1(String str) {
        selectedcourse1 = str;
    }

    void setselectedcourse2(String str) {
        selectedcourse2 = str;
    }

    void setselectedcourse3(String str) {
        selectedcourse3 = str;
    }

    void setspwd(String str) {
        spwd = str;
    }

    //获取变量
    String getsno() {
        return sno;
    }

    String getsname() {
        return sname;
    }

    String getssex() {
        return ssex;
    }

    int getsage() {
        return sage;
    }

    String getpross() {
        return pross;
    }

    String getspwd() {
        return spwd;
    }

    String getselectedcourse1() {
        return selectedcourse1;
    }

    String getselectedcourse2() {
        return selectedcourse2;
    }

    String getselectedcourse3() {
        return selectedcourse3;
    }

    //获取数据库连接
    sqlconnect sqlcnt = new sqlconnect();


    void add() {
        String sql = "insert into student (sno,sname,ssex,sage,pross,spwd) values (?,?,?,?,?,?)";
        try {
            PreparedStatement addpreparedstatement = sqlcnt.con.prepareStatement(sql);
            addpreparedstatement.setString(1, sno);//sno
            addpreparedstatement.setString(2, sname);//sname
            addpreparedstatement.setString(3, ssex);//ssex
            addpreparedstatement.setInt(4, sage);//sage
            addpreparedstatement.setString(5, pross);//pross
            addpreparedstatement.setString(6, spwd);//spwd
            i = addpreparedstatement.executeUpdate();
            System.out.println("成功添加" + i + "条记录。");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    void update() {
        String sql = "update student set sno=?,sname=?,ssex=?,sage=?,pross=?,spwd=? where sno ='" + sno + "'";
        try {
            PreparedStatement updatapreparedstatement = sqlcnt.con.prepareStatement(sql);
            updatapreparedstatement.setString(1, sno);//sno
            updatapreparedstatement.setString(2, sname);//sname
            updatapreparedstatement.setString(3, ssex);//ssex
            updatapreparedstatement.setInt(4, sage);//sage
            updatapreparedstatement.setString(5, pross);//pross
            updatapreparedstatement.setString(6, spwd);//spwd
            i = updatapreparedstatement.executeUpdate();
            updatapreparedstatement.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    void delete() {
        String sql = "delete from student where sno='" + sno + "'";
        try {
            Statement deletestatement = sqlcnt.con.createStatement();
            i = deletestatement.executeUpdate(sql);
            System.out.println("成功删除" + i + "条记录。");
            deletestatement.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    void updatecourse() {
        String sql = "update student set selectedcourse1=?,selectedcourse2=?,selectedcourse3=? where sno ='" + sno + "'";
        try {
            PreparedStatement updatapreparedstatement = sqlcnt.con.prepareStatement(sql);
            updatapreparedstatement.setString(1, selectedcourse1);//selectedcourse1
            updatapreparedstatement.setString(2, selectedcourse2);//selectedcourse2
            updatapreparedstatement.setString(3, selectedcourse3);//selectedcourse3
            i = updatapreparedstatement.executeUpdate();
            JOptionPane.showMessageDialog(null, "课程更改成功", "提示", JOptionPane.PLAIN_MESSAGE);
            updatapreparedstatement.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

class teacher {
    int i;
    //教师信息
    String tno;
    String tname;
    String tsex;
    int tage;
    String tpt;//职称
    String teachercourse1;
    String teachercourse2;
    String teachercourse3;
    String tpwd;

    //教师方法
    //设置变量
    void settno(String str) {
        tno = str;
    }

    void settname(String str) {
        tname = str;
    }

    void settsex(String str) {
        tsex = str;
    }

    void settage(int x) {
        tage = x;
    }

    void settpt(String str) {
        tpt = str;
    }

    void settpwd(String str) {
        tpwd = str;
    }

    void setteachercourse1(String str) {
        teachercourse1 = str;
    }

    void setteachercourse2(String str) {
        teachercourse2 = str;
    }

    void setteachercourse3(String str) {
        teachercourse3 = str;
    }

    //返回变量
    String gettno() {
        return tno;
    }

    String gettname() {
        return tname;
    }

    String gettsex() {
        return tsex;
    }

    int gettage() {
        return tage;
    }

    String gettpt() {
        return tpt;
    }

    String getteachercourse1() {
        return teachercourse1;
    }

    String getteachercourse2() {
        return teachercourse2;
    }

    String getteachercourse3() {
        return teachercourse3;
    }

    String gettpwd() {
        return tpwd;
    }

    //获取数据库连接
    sqlconnect sqlcnt = new sqlconnect();

    void add() {
        String sql = "insert into teacher (tno,tname,tsex,tage,tpt,tpwd) values (?,?,?,?,?,?)";
        try {
            PreparedStatement addpreparedstatement = sqlcnt.con.prepareStatement(sql);
            addpreparedstatement.setString(1, tno);//tno
            addpreparedstatement.setString(2, tname);//tname
            addpreparedstatement.setString(3, tsex);//tsex
            addpreparedstatement.setInt(4, tage);//tage
            addpreparedstatement.setString(5, tpt);//tpt
            addpreparedstatement.setString(6, tpwd);//tpwd
            i = addpreparedstatement.executeUpdate();
            System.out.println("成功添加" + i + "条记录。");
            addpreparedstatement.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    void update() {
        String sql = "update teacher set tno=?,tname=?,tsex=?,tage=?,tpt=?,tpwd=? where tno ='" + tno + "'";
        try {
            PreparedStatement updatapreparedstatement = sqlcnt.con.prepareStatement(sql);
            updatapreparedstatement.setString(1, tno);//tno
            updatapreparedstatement.setString(2, tname);//tname
            updatapreparedstatement.setString(3, tsex);//tsex
            updatapreparedstatement.setInt(4, tage);//tage
            updatapreparedstatement.setString(5, tpt);//tpt
            updatapreparedstatement.setString(6, tpwd);//tpwd
            i = updatapreparedstatement.executeUpdate();
            updatapreparedstatement.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    void delete() {
        String sql = "delete from teacher where tno='" + tno + "'";
        try {
            Statement deletestatement = sqlcnt.con.createStatement();
            i = deletestatement.executeUpdate(sql);
            System.out.println("成功删除" + i + "条记录。");
            deletestatement.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}


class course {
    int i;
    //课程信息
    String cno;
    String cname;
    String cteacher;
    String ctno;
    int credit;//学分
    int capacity;//容量

    //课程方法
    //设置变量
    void setcno(String str) {
        cno = str;
    }

    void setcname(String str) {
        cname = str;
    }

    void setcteacher(String str) {
        cteacher = str;
    }

    void setctno(String str) {
        ctno = str;
    }

    void setcredit(int x) {
        credit = x;
    }

    void setcapacity(int x) {
        capacity = x;
    }

    //返回变量
    String getcno() {
        return cno;
    }

    String getcname() {
        return cname;
    }

    String getcteacher() {
        return cteacher;
    }

    String gettno() {
        return ctno;
    }

    int getcredit() {
        return credit;
    }

    int getcapacity() {
        return capacity;
    }

    //获取数据库连接
    sqlconnect sqlcnt = new sqlconnect();

    void add() {
        String sql = "insert into course (cno,cname,cteacher,ctno,credit,capacity) values (?,?,?,?,?,?)";
        int i = 0;
        try {
            PreparedStatement addpreparedstatement = sqlcnt.con.prepareStatement(sql);
            addpreparedstatement.setString(1, cno);//cno
            addpreparedstatement.setString(2, cname);//cname
            addpreparedstatement.setString(3, cteacher);//cteacher
            addpreparedstatement.setString(4, ctno);//ctno
            addpreparedstatement.setInt(5, credit);//credit
            addpreparedstatement.setInt(6, capacity);//capacity
            i = addpreparedstatement.executeUpdate();
            System.out.println("成功添加" + i + "条记录。");
            addpreparedstatement.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    void update() {
        String sql = "update student set cno=?,cname=?,cteacher=?,credit=?,capacity=? where id =" + cno;
        try {
            PreparedStatement updatepreparedstatement = sqlcnt.con.prepareStatement(sql);
            updatepreparedstatement.setString(1, cno);//cno
            updatepreparedstatement.setString(2, cname);//cname
            updatepreparedstatement.setString(3, cteacher);//cteacher
            updatepreparedstatement.setInt(4, credit);//credit
            updatepreparedstatement.setInt(5, capacity);//capacity
            i = updatepreparedstatement.executeUpdate();
            System.out.println("成功添加" + i + "条记录。");
            updatepreparedstatement.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    void delete() {
        String sql = "delete from course where cno='" + cno + "'";
        try {
            Statement deletestatement = sqlcnt.con.createStatement();
            i = deletestatement.executeUpdate(sql);
            System.out.println("成功删除" + i + "条记录。");
            deletestatement.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

class cselect {
    int i, j;
    //选课信息
    String cno;

    String cname;

    String sno;
    String sname;
    String tno;
    String tname;

    //选课方法
    //设置变量
    void setcno(String str) {
        cno = str;
    }

    void setcname(String str) {
        cname = str;
    }

    void setsno(String str) {
        sno = str;
    }

    void setsname(String str) {
        sname = str;
    }

    void settno(String str) {
        tno = str;
    }

    void settname(String str) {
        tname = str;
    }

    //返回变量
    String getcno() {
        return cno;
    }

    String getcname() {
        return cname;
    }

    String getsno() {
        return sno;
    }

    String getsname() {
        return sname;
    }

    String gettno() {
        return tno;
    }

    String gettname() {
        return tname;
    }

    //获取数据库连接
    sqlconnect sqlcnt = new sqlconnect();

    void add() {
        String sql = "insert into cselect (cno,cname,sno,sname,tno,tname) values (?,?,?,?,?,?)";
        int i = 0;
        try {
            PreparedStatement addpreparedstatement = sqlcnt.con.prepareStatement(sql);
            addpreparedstatement.setString(1, cno);//cno
            addpreparedstatement.setString(2, cname);//cname
            addpreparedstatement.setString(3, sno);//sno
            addpreparedstatement.setString(4, sname);//sname
            addpreparedstatement.setString(5, tno);//tno
            addpreparedstatement.setString(6, tname);//tname
            i = addpreparedstatement.executeUpdate();
            System.out.println("成功添加" + i + "条记录。");
            addpreparedstatement.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    void delete() {
        try {
            Statement deletestatement = sqlcnt.con.createStatement();
            i = deletestatement.executeUpdate("delete from cselect where sno='" + sno + "' and tno='" + tno + "' and  cno='" + cno + "'");
            System.out.println("成功删除" + i + "条记录。");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

class admin {
    int i;
    String adno;
    String adname;
    String adpwd;

    //设置变量
    void setadno(String str) {
        adno = str;
    }

    void setadname(String str) {
        adname = str;
    }

    void setadpwd(String str) {
        adpwd = str;
    }

    //返回变量
    String getadno(String str) {
        return adno;
    }

    String getadname(String str) {
        return adname;
    }

    String getadpwd(String str) {
        return adpwd;
    }

    //获取数据库连接
    sqlconnect sqlcnt = new sqlconnect();

    void update() {
        String sql = "update admin set adno=?,adname=?,adpwd=? where adno ='" + adno + "'";
        try {
            PreparedStatement updatapreparedstatement = sqlcnt.con.prepareStatement(sql);
            updatapreparedstatement.setString(1, adno);//adno
            updatapreparedstatement.setString(2, adname);//adname
            updatapreparedstatement.setString(3, adpwd);//adpwd
            i = updatapreparedstatement.executeUpdate();
            updatapreparedstatement.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

class sqlconnect {
    String driver = "com.mysql.cj.jdbc.Driver";
    String sqlurl = "jdbc:mysql://localhost:3306/cms?characterEncoding=UTF-8";
    String sqluesrname = "root";
    String sqluserpassword = "123456";
    Connection con = getcon();

    Connection getcon() {
        Connection con = null;
        try {  ////加载驱动程序
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try {
            con = DriverManager.getConnection(sqlurl, sqluesrname, sqluserpassword);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return con;
    }
}
